/**
 * 게시판과 관련된 자바스크립트
 * date: 2014.11.03
 * author: th
 */

var url = "index.jsp?inc=../boards/";

function general(){//게시판에서 사용되는 공통 모듈
	
	if(document.getElementById("btnList") != null){		
		document.getElementById("btnList").onclick = function(){
			location.href = "/kiSunnyShop/boards/list.jsp";
		}
	}
	if(document.getElementById("btnInput") != null){
		document.getElementById("btnInput").onclick = function(){
			location.href = "input.jsp";
		}
	}
	if(document.getElementById("btnRepInput") != null){
		document.getElementById("btnRepInput").onclick = function(){
			var f = document.hiddenFrm;
			f.action = "/kiSunnyShop/boards/rep_input.jsp";
			f.submit();
			
		}
	}
	if(document.getElementById("btnModify") != null){
		document.getElementById("btnModify").onclick = function(){
			location.href = "modify.jsp";
		}
	}
	if(document.getElementById("btnDelete") != null){
		document.getElementById("btnDelete").onclick = function(){
			location.href = "delete_result.jsp";
		}
	}
	if(document.getElementById("btnView") != null){
		document.getElementById("btnView").onclick = function(){
			location.href = "view.jsp";
		}
	}
}

function goPage(page){
	
	location.href = "view.jsp&page="+page;
}

function inputInit(){
	
	
	if(document.getElementById("btnList") != null){		
		document.getElementById("btnList").onclick = function(){
			location.href = "/kiSunnyShop/boards/list.jsp";
		}
	}
	document.getElementById("btnSave").onclick = function(){
		var f = document.bfrm;
		if(f.subject.value == ""){
			alert("제목을 입력하세요.");
			f.subject.focus();
		}else{
			f.submit();
		}
	}
}

function repInputInit(){
	
	general();
	document.getElementById("btnRepSave").onclick = function(){
		var f = document.rep_frm;
		if(f.title.value == ""){
			alert("내용을 입력하세요.");
			f.title.focus();
		}else{
			f.submit();
		}
	}
}

function goPage(page){
	
	var mf = document.hiddenFrm;
	mf.nowPage.value = page;
	mf.find.value = document.board_list_frm.find.value;
	mf.action = url+"list.jsp";
	mf.submit();
}

function goView(page, no){
	
	var mf = document.hiddenFrm;
	mf.nowPage.value = page;
	mf.no.value = no;
	mf.find.value = document.board_list_frm.find.value;
	mf.action = "view.jsp";
	mf.submit();
}

function listInit(){
	
	general();
}

function viewInit(){
	
	general();
}

function modifyInit(){
	
	general();
	document.getElementById("btnSave").onclick = function(){
		var f = document.frm;
		if(f.title.value == ""){
			alert("제목을 입력해주세요.");
			f.title.focus();
		}else{
			f.submit();
		}
	}
}

function deleteInit(){
	
	general();
}
